
import {Component} from 'react';
import { Boxs, Group } from 'saltui';
const { HBox, Box } = Boxs;

export default class CheckTimeField extends Component{

  constructor(props){
    super(props);
    let hours=["00:00","01:00","02:00","03:00","04:00","05:00",
    "06:00","07:00","08:00","09:00","10:00","11:00",
    "12:00","13:00","14:00","15:00","16:00","17:00",
    "18:00","19:00","20:00","21:00","22:00","23:00","24:00"];
    this.state = {
      hours: hours
    }
  }
  click(url){
    if(url){
      location.hash = url;
    }
  }
  render() {
    let startTime = this.props.startTime.split(":");
    let startHours = parseInt(startTime[0]);
    let startNum = parseInt(startTime[1])/15;
    let endTime = this.props.endTime.split(":");
    let endHours = parseInt(endTime[0]);
    let endNum = parseInt(endTime[1])/15;
    let times = this.props.times.split(",");
    let indexMap = [1,2,3,4];
    //需求:只让其显示会议室设置时间段 modify by zhaozy 20210804
    let hours=this.state.hours.slice(this.state.hours.indexOf(startTime[0]+":00"),this.state.hours.indexOf(endTime[0]+":00")+(endTime[1]!="00"?1:0));
    const lists = hours.map((item, index) => {
      let boxHtml = indexMap.map((item1,index1) => {
        let style = {background:'#89be76', borderColor:'#89be76'};
        /*if(index < startHours || (index == startHours && index1 < startNum) || index > endHours || (index == endHours && index1 >= endNum)){
          style.background = '#ccc'; 
          style.borderColor = '#ccc'; 
        }*/
        if((index==0 && index1 < startNum )|| (index==hours.length-1 && index1 >= endNum)){
          style.background = '#ccc'; 
          style.borderColor = '#ccc'; 
        }
        var detailUrl="";
        var currentIndex = (startHours+index)*4 + item1;
        for(let i=0;i<times.length;i++){
          if(times[i].split(".")[0]==currentIndex){
            style.background = '#ff9b43'; 
            style.borderColor = '#ff9b43';
            // if(times[i].split(".")[2]=="true"){
            //   detailUrl="meeting/myMeetingDetails/"+times[i].split(".")[1]+"/myReceived";
            // }
            detailUrl="meeting/myMeetingDetails/"+times[i].split(".")[1]+"/myReceived";
            break; 
          }
        }
        
        return (
          <Box style={style} onClick={this.click.bind(this,detailUrl)}></Box>
        );
      });
      return (
        <li className="t-DIB t-MR10">
          <Box className="t-FCddfontblue-60">{item}</Box>
          <HBox className="time-slider">
            {boxHtml}
          </HBox>
        </li>
      );
    });
    return (
      <Group.List>
        <div className="t-P16 slider-show">
          <ul>
            {lists}
          </ul>
        </div>
      </Group.List>
    );
  }
}

